<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.*,hotel.entity.*"%>
<%@include file="../link.html"%>
<!DOCTYPE html>
<script type="text/javascript">
$(document).ready(function() {
	$("#btn-close").click( function () { 
		var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		parent.layer.close(index); //再执行关闭 
	});
});

function saveRoom(){
	var index=$('#btn-submit').attr('class').indexOf("disabled");
	if(index==-1){//disabled的下标为-1说明确定按钮可用
		$.ajax({
	        type:"post",
	        url:"addRoom",
	        data: $('#roomForm').serialize(),//表单数据
	        success: function(data){
				layer.msg('创建成功', {icon: 1, time: 800}, function(){//关闭后执行的操作
						var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
						parent.layer.close(index); //再执行关闭 
					});  
	        }
	    });
	}
	return false;
}
</script>

<div style="padding-top:25px;">
	<form id="roomForm" action="addRoom" method="post" class="form-horizontal" 
	data-toggle="validator" role="form">
	
		<div class="form-group">
			<label class="col-sm-4 control-label">房间类型</label>
			<div class="col-sm-5">
				<select name="category.categoryid" id="category.categoryid"  class="form-control">
				<% 
					List<Category> list=(List<Category>)request.getAttribute("categoryList");
					for(Category c:list){
						out.print("<option value='"+c.getCategoryid()+"'>"+c.getCategoryName()+"</option>");
					}
				%>
				</select>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-4 control-label">房间编号</label>
			<div class="col-sm-5">
				<input id="no" name="no" class="form-control" autofocus="autofocus" required>
			</div>
			<div class="help-block with-errors"></div>
		</div>

		<div class="form-group">
			<label class="col-sm-4 control-label">房间面积</label>
			<div class="col-sm-5">
				<input id="area" name="area" class="form-control" required>
			</div>
			<div class="help-block with-errors"></div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-4 control-label">所在楼层</label>
			<div class="col-sm-5">
				<input id="floor" name="floor" class="form-control" required>
			</div>
			<div class="help-block with-errors"></div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-4 control-label">状态</label>
			<div class="col-sm-5">
				<select name="state" id="state" class="form-control">
					<option value="空">空</option>
					<option value="已入住">已入住</option>
					<option value="打扫中">打扫中</option>
					<option value="禁用">禁用</option>
				</select>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-4 control-label">房间详情</label>
			<div class="col-sm-5">
				<textarea id="detail" name="detail" class="form-control"></textarea>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-4 control-label">上传图片</label>
			<div class="col-sm-5">
				
			</div>
		</div>
		
		<div class="box-footer"></div>
		
		<div class="form-group">
			<label class="col-sm-4 control-label"></label>
			<div class="col-sm-5">
				<div class="pull-right">
					<button id="btn-submit" type="submit" class="btn btn-primary" onClick="return saveRoom()">
						<i class="fa fa-floppy-o "></i> 确定
					</button>
					<button id="btn-close" class="btn btn-close btn-primary" type="button">
						<i class="fa fa-remove"></i> 关闭
					</button>
				</div>
			</div>
		</div>
	</form>
</div>